#include"user_ui.h"
#include"value.h"
#include"goods_list_op.h"
#include"admin_ui.h"
#include"user_list.h"
#include"login_ui.h"
#include"General_func.h"
lv_obj_t *Shopping_cart;
lv_obj_t *User_tab;
//自动关闭窗口
void auto_close_win(lv_obj_t *win)
{
    lv_obj_del(win); // 删除窗口
    win = NULL;
}

//确认支付
void check_out_pay_event_cb(lv_event_t *e)
{
    goods_cart *cart = lv_event_get_user_data(e);
    char *amount_str = lv_label_get_text(cart->tmp1);
    float amount = atof(amount_str);
    //折扣后金额
    amount = amount*(cur_user.discount);

    char *txt = lv_label_get_text(cart->tmp2);
    int vip = 0;
    int flag = 0;//默认直接支付
    if(strcmp(txt,"Wallet payment")==0)
    {
        flag = 1;//钱包支付 
    }else if(strcmp(txt,"VIP") == 0)
    {
        vip = 1;
    }
    
    if(flag == 0)
    {
        if(cur_user.identity == 1)
        {
            int credit = (int)(amount*10);
            User *tmp = user_find_node_by_username(user_list,cur_user.username);
            tmp->credits = tmp->credits + credit;
            lv_obj_t * mbox = lv_msgbox_create(NULL, "success", "Payment successful", NULL, true);
            lv_obj_center(mbox);
            if(vip == 1)
            {
                tmp->identity = 2;
                user_file_save_data(user_list,"user.txt");
                cur_login_user_info(tmp);
                auto_close_win(cart->tmp3);
            }else{
                cur_login_user_info(tmp);
                input_win = NULL;
                cart_cont = NULL;//刷新购物界面购物车
                shop_cart_cont = NULL;//刷新购物车界面购物车
                // Shopping_tab_ui(Shopping_cart);
                user_ui_init();
            }
        }else{
            int credit = (int)(amount*30);
            User *tmp = user_find_node_by_username(user_list,cur_user.username);
            tmp->credits = tmp->credits + credit;
            lv_obj_t * mbox = lv_msgbox_create(NULL, "success", "Payment successful", NULL, true);
            lv_obj_center(mbox);
            cur_login_user_info(tmp);
            //关闭之前窗口
            input_win = NULL;
            cart_cont = NULL;//刷新购物界面购物车
            // Shopping_tab_ui(Shopping_cart);
            shop_cart_cont = NULL;//刷新购物车界面购物车

            user_ui_init();
        }
    }else if(flag == 1){
        if(cur_user.balance - amount >= 0)
        {
            if(cur_user.identity == 1)
            {
                int credit = (int)(amount*20);
                User *tmp = user_find_node_by_username(user_list,cur_user.username);
                tmp->credits = tmp->credits + credit;
                tmp->balance = tmp->balance - amount;

                lv_obj_t * mbox = lv_msgbox_create(NULL, "success", "Payment successful", NULL, true);
                lv_obj_center(mbox);
                cur_login_user_info(tmp);
                input_win = NULL;
                cart_cont = NULL;//刷新购物界面购物车
                shop_cart_cont = NULL;//刷新购物车界面购物车
                // Shopping_tab_ui(Shopping_cart);
                user_ui_init();
            }else{
                int credit = (int)(amount*40);
                User *tmp = user_find_node_by_username(user_list,cur_user.username);
                tmp->credits = tmp->credits + credit;
                tmp->balance = tmp->balance - amount;

                lv_obj_t * mbox = lv_msgbox_create(NULL, "success", "Payment successful", NULL, true);
                lv_obj_center(mbox);
                cur_login_user_info(tmp);
                input_win = NULL;
                cart_cont = NULL;//刷新购物界面购物车
                shop_cart_cont = NULL;//刷新购物车界面购物车
                // Shopping_tab_ui(Shopping_cart);
                user_ui_init();
            }
        }else{
            lv_obj_t * mbox = lv_msgbox_create(NULL, "error", "Insufficient balance in the wallet", NULL, true);
            lv_obj_center(mbox);
            return;
        }
    }

}

//关闭支付窗口
void close_pay_win_event(lv_event_t *e) {
    lv_obj_t *win = lv_event_get_user_data(e);
    lv_obj_del(win); // 删除窗口
    win = NULL;
}

//最终支付界面
void payment_ui_event_cb(lv_event_t *e)
{
    // 创建模态背景窗口
    lv_obj_t *pay_win = lv_win_create(lv_scr_act(), 50);
    lv_obj_set_size(pay_win, 800, 480);
    lv_obj_center(pay_win);
    lv_win_add_title(pay_win, "payment-ui");
    // 关闭标志
    lv_obj_t *close_btn = lv_win_add_btn(pay_win, LV_SYMBOL_CLOSE, 50);
    lv_obj_add_event_cb(close_btn, close_pay_win_event, LV_EVENT_CLICKED, pay_win);

    lv_obj_t *target = lv_event_get_target(e);
    lv_obj_t *label = lv_obj_get_child(target,0);

    lv_obj_t *origin_amount_label = lv_event_get_user_data(e);
    char *amount_str = lv_label_get_text(origin_amount_label);
    float amount = atof(amount_str);
    //折扣后金额
    amount = amount*(cur_user.discount);

    char amount_str2[100];
    snprintf(amount_str2,sizeof(amount_str2),"The total amount for this time is %.2f yuan.",amount);

    char *txt = lv_label_get_text(label);
    int flag = 0;//默认直接支付
    if(strcmp(txt,"Wallet payment")==0)
    {
        flag = 1;//钱包支付 
    }

    //支付界面
    lv_obj_t *payment_scr = lv_obj_create(pay_win);
    lv_obj_set_size(payment_scr,800,430);
    lv_obj_set_style_border_width(payment_scr, 0, 0);
    lv_obj_set_style_pad_all(payment_scr, 0, 0);
    //    背景
    lv_obj_t *img = lv_img_create(payment_scr);
    //    设置图片源
    LV_IMG_DECLARE(check_out_bg_img);
    lv_img_set_src(img,&check_out_bg_img);
    lv_obj_set_size(img,800,430);

    //金额
    lv_obj_t *amount_cont = lv_obj_create(payment_scr);
    lv_obj_set_size(amount_cont,400,80);
    lv_obj_align(amount_cont,LV_ALIGN_CENTER,0,-100);

    //金额标签
    lv_obj_t *amount_label = lv_label_create(amount_cont);
    lv_label_set_text(amount_label,amount_str2);
    lv_obj_center(amount_label);

    //确认支付
    lv_obj_t *Confirm_pay = lv_btn_create(payment_scr);
    lv_obj_set_size(Confirm_pay,150,50);
    lv_obj_set_style_bg_color(Confirm_pay,lv_palette_main(LV_PALETTE_LIGHT_GREEN),0);
    lv_obj_align(Confirm_pay,LV_ALIGN_CENTER,0,10);
    //支付标签
    lv_obj_t *Confirm_label = lv_label_create(Confirm_pay);
    lv_label_set_text(Confirm_label,"Confirm payment");
    lv_obj_center(Confirm_label);

    goods_cart *cart = malloc(sizeof(goods_cart));
    cart->tmp1 = origin_amount_label;//最初金额
    cart->tmp2 = label;//支付方式
    cart->tmp3 = pay_win;//窗口
    User_tab_ui(User_tab);
    lv_obj_add_event_cb(Confirm_pay,check_out_pay_event_cb,LV_EVENT_CLICKED,cart);
}

//办理vip
void apply_vip_win_cb(lv_event_t *e)
{
    // 创建模态背景窗口
    lv_obj_t *apply_vip_win = lv_win_create(lv_scr_act(), 50);
    lv_obj_set_size(apply_vip_win, 800, 480);
    lv_obj_center(apply_vip_win);
    lv_win_add_title(apply_vip_win, "Apply-vip");
    // 关闭标志
    lv_obj_t *close_btn = lv_win_add_btn(apply_vip_win, LV_SYMBOL_CLOSE, 50);
    lv_obj_add_event_cb(close_btn, close_pay_win_event, LV_EVENT_CLICKED, apply_vip_win);

    //支付界面
    lv_obj_t *apply_vip_scr = lv_obj_create(apply_vip_win);
    lv_obj_set_size(apply_vip_scr,800,430);
    lv_obj_set_style_border_width(apply_vip_scr, 0, 0);
    lv_obj_set_style_pad_all(apply_vip_scr, 0, 0);

    //金额
    lv_obj_t *amount_cont = lv_obj_create(apply_vip_scr);
    lv_obj_set_size(amount_cont,200,80);
    lv_obj_align(amount_cont,LV_ALIGN_CENTER,0,-100);

    //金额标签
    lv_obj_t *amount_label = lv_label_create(amount_cont);
    lv_label_set_text(amount_label,"Total amount is 30");
    lv_obj_center(amount_label);

    lv_obj_t *wx_pay = lv_btn_create(apply_vip_scr);
    lv_obj_set_size(wx_pay,100,100);
    lv_obj_set_style_border_width(wx_pay, 0, 0);
    lv_obj_set_style_pad_all(wx_pay, 0, 0);
    lv_obj_set_style_radius(wx_pay,30,0);
    lv_obj_align(wx_pay,LV_ALIGN_CENTER,0,0);
    //    背景
    lv_obj_t *img = lv_img_create(wx_pay);
    //    设置图片源
    LV_IMG_DECLARE(wxpay_bg_img);
    lv_img_set_src(img,&wxpay_bg_img);
    lv_obj_set_size(img,100,100);
    lv_obj_set_style_radius(img,30,0);

    lv_obj_t *vip = lv_label_create(apply_vip_scr);
    lv_label_set_text(vip,"VIP");
    lv_obj_align_to(vip,amount_cont,LV_ALIGN_OUT_TOP_MID,0,30);

    goods_cart *cart = malloc(sizeof(goods_cart));//
    cart->tmp1 = amount_label;//最初金额
    cart->tmp2 = vip;//支付方式
    cart->tmp3 = apply_vip_win;//窗口

    lv_obj_add_event_cb(wx_pay,check_out_pay_event_cb,LV_EVENT_CLICKED,cart);

}

//创建选择支付的窗口
void create_check_out_window(lv_event_t *e) {
    if(input_win) return; // 防止重复创建

    lv_obj_t *target = lv_event_get_target(e);
    lv_obj_t *label = lv_obj_get_child(target,0);
    char *txt = lv_label_get_text(label);
    lv_obj_t *cur_amount = lv_event_get_user_data(e);
    
    //最低起送费 1元 ----------------------------
    char *cur_str = lv_label_get_text(cur_amount);
    float cur_amount_f = atof(cur_str);
    if(cur_amount_f < 1)
    {
        lv_obj_t * mbox = lv_msgbox_create(NULL, "error", "The minimum starting charge is one yuan.", NULL, true);
        lv_obj_center(mbox);
        return;
    }   
    //--------------------------------------------------

    // 创建模态背景窗口
    input_win = lv_win_create(lv_scr_act(), 50);
    lv_obj_set_size(input_win, 800, 480);
    lv_obj_center(input_win);
    lv_win_add_title(input_win, "check out");
    // 关闭标志
    lv_obj_t *close_btn = lv_win_add_btn(input_win, LV_SYMBOL_CLOSE, 50);
    lv_obj_add_event_cb(close_btn, close_win_event, LV_EVENT_CLICKED, NULL);

    //设置键盘
    keyboard = lv_keyboard_create(lv_scr_act());
    lv_keyboard_set_textarea(keyboard, NULL);
    lv_obj_add_flag(keyboard, LV_OBJ_FLAG_HIDDEN);

    // 创建内容容器
    lv_obj_t * cont = lv_win_get_content(input_win);
    lv_obj_set_size(cont,800,430);
    lv_obj_set_style_border_width(cont, 0, 0);
    lv_obj_set_style_pad_all(cont, 0, 0);

    //    背景
    lv_obj_t *img = lv_img_create(cont);
    //    设置图片源
    LV_IMG_DECLARE(check_out_bg_img);
    lv_img_set_src(img,&check_out_bg_img);
    lv_obj_set_size(img,800,430);
    //"请选择支付方式标签" : 直接支付、钱包支付、办理vip
    lv_obj_t *payment_method_label = lv_label_create(cont);
    lv_label_set_text(payment_method_label,"Please select the payment method.");
    lv_obj_set_style_text_font(payment_method_label,&lv_font_montserrat_30,0);
    lv_obj_align(payment_method_label,LV_ALIGN_TOP_MID,0,10);

    //  直接支付
    lv_obj_t * Direct_payment_btn = lv_btn_create(cont);
    lv_obj_set_size(Direct_payment_btn,200,60);
    lv_obj_set_style_border_width(Direct_payment_btn, 0, 0);
    lv_obj_set_style_pad_all(Direct_payment_btn, 0, 0);
    lv_obj_align(Direct_payment_btn,LV_ALIGN_CENTER,-130,-20);

    lv_obj_t *direct_payment_label = lv_label_create(Direct_payment_btn);
    lv_label_set_text(direct_payment_label,"Direct payment");
    lv_obj_center(direct_payment_label);

    //  钱包支付
    lv_obj_t * Wallet_payment_btn = lv_btn_create(cont);
    lv_obj_set_size(Wallet_payment_btn,200,60);
    lv_obj_set_style_border_width(Wallet_payment_btn, 0, 0);
    lv_obj_set_style_pad_all(Wallet_payment_btn, 0, 0);
    lv_obj_align(Wallet_payment_btn,LV_ALIGN_CENTER,130,-20);

    lv_obj_t *Wallet_payment_label = lv_label_create(Wallet_payment_btn);
    lv_label_set_text(Wallet_payment_label,"Wallet payment");
    lv_obj_center(Wallet_payment_label);

    if(cur_user.identity == 1)//普通用户
    {
        lv_obj_t * mbox = lv_msgbox_create(NULL, "Reminder", "Currently, you are an ordinary user. \nIf you apply for VIP status, you will be entitled to discounts.", NULL, true);
        lv_obj_center(mbox);

        //办理vip
        lv_obj_t * apply_vip_btn = lv_btn_create(cont);
        lv_obj_set_size(apply_vip_btn,150,60);
        lv_obj_set_style_border_width(apply_vip_btn, 0, 0);
        lv_obj_set_style_pad_all(apply_vip_btn, 0, 0);
        lv_obj_align(apply_vip_btn,LV_ALIGN_CENTER,0,50);
        lv_obj_set_style_bg_color(apply_vip_btn,lv_palette_main(LV_PALETTE_GREEN),0);

        lv_obj_t *apply_vip_label = lv_label_create(apply_vip_btn);
        lv_label_set_text(apply_vip_label,"Apply VIP");
        lv_obj_center(apply_vip_label);
        lv_obj_add_event_cb(apply_vip_btn,apply_vip_win_cb,LV_EVENT_CLICKED,NULL);
    }

    lv_obj_add_event_cb(Direct_payment_btn,payment_ui_event_cb,LV_EVENT_CLICKED,cur_amount);
    lv_obj_add_event_cb(Wallet_payment_btn,payment_ui_event_cb,LV_EVENT_CLICKED,cur_amount);
}

//添加或减少商品到购物车
void add_or_reduce_to_cart_event_cb(lv_event_t *e)
{
    lv_obj_t *target = lv_event_get_target(e);
    lv_obj_t *label = lv_obj_get_child(target,0);
    goods_cart *cart = lv_event_get_user_data(e);
    //判断加、减
    char *txt = lv_label_get_text(label);
    int flag = 0 ;//默认点击加
    if(strcmp(txt,LV_SYMBOL_MINUS) == 0)
    {
        flag = 1;
    }

    char *goods_name = lv_label_get_text(cart->tmp1);

    Goodslist *tmp = find_node_by_name(goods_list,goods_name);
    if(tmp == NULL)
    {
        lv_obj_t * mbox = lv_msgbox_create(NULL, "Reminder", "This product is not available.", NULL, true);
        lv_obj_center(mbox);
        return;
    }

    //获取当前商品添加数量
    char *goods_select_num = lv_label_get_text(cart->tmp4);
    int cur_num = atoi(goods_select_num);
    char buf_cur_select_goods_num[20];

    //获取当前购物车总金额
    char *cart_account = lv_label_get_text(cart->tmp5);
    float cur_account = atof(cart_account);
    char buf_cur_cart_account[20];

    //剩余商品数量
    char buf_cur_remain_num[20];
    if(flag == 0)//点击加
    {
        if((tmp->quantity - 1) >= 0)
        {
            tmp->quantity = tmp->quantity - 1;//货品数量减一
            //剩余库存
            snprintf(buf_cur_cart_account,sizeof(buf_cur_cart_account),"%d",tmp->quantity);
            buf_cur_cart_account[strlen(buf_cur_cart_account)] = '\0';
            lv_label_set_text(cart->tmp3,buf_cur_cart_account);

            //选择商品数量
            cur_num++;
            snprintf(buf_cur_select_goods_num,sizeof(buf_cur_select_goods_num),"%d",cur_num);
            buf_cur_select_goods_num[strlen(buf_cur_select_goods_num)] = '\0';
            lv_label_set_text(cart->tmp4,buf_cur_select_goods_num);


            //购物车总金额
            cur_account += tmp->price;
            snprintf(buf_cur_cart_account,sizeof(buf_cur_cart_account),"%.2f",cur_account);
            buf_cur_cart_account[strlen(buf_cur_cart_account)] = '\0';
            lv_label_set_text(cart->tmp5,buf_cur_cart_account);

            //shopcart的总金额
            lv_label_set_text(shop_cart_cont->current_amount,buf_cur_cart_account);
            Cart_goods cart_good = {
                .quantity = cur_num,
                .remainder = tmp->quantity,
                .quantity_label = cart->tmp4,
                .remainder_label = cart->tmp3,
            };
            strcpy(cart_good.name,tmp->name);
            Cart_goods_list *find =  cart_goods_find_node_by_name(cart_goods_list,tmp->name);

            if(find == NULL)
            {
                Cart_goods_list *new = Cart_goods_new_node(cart_good);//新建
                Cart_goods_insert_node(cart_goods_list,new);//插入
            }else{

                find->quantity = find->quantity+1;
                find->remainder = find->remainder-1;
            }
            if(cart->tmp6 != NULL)
            {
                lv_label_set_text(cart->tmp6,buf_cur_select_goods_num);//当前选择的商品数量
            }
            Shopping_tab_ui(Shopping_cart);
        }else{
            lv_obj_t * mbox = lv_msgbox_create(NULL, "Reminder", "Insufficient inventory", NULL, true);
            lv_obj_center(mbox);
            return;
        }
    }else{
        if( cur_num > 0)
        {
            tmp->quantity = tmp->quantity + 1;//货品数量减一
            //剩余库存
            snprintf(buf_cur_cart_account,sizeof(buf_cur_cart_account),"%d",tmp->quantity);
            buf_cur_cart_account[strlen(buf_cur_cart_account)] = '\0';
            lv_label_set_text(cart->tmp3,buf_cur_cart_account);

            //选择商品数量
            cur_num--;
            snprintf(buf_cur_select_goods_num,sizeof(buf_cur_select_goods_num),"%d",cur_num);
            buf_cur_select_goods_num[strlen(buf_cur_select_goods_num)] = '\0';
            lv_label_set_text(cart->tmp4,buf_cur_select_goods_num);

            //购物车总金额
            cur_account -= tmp->price;
            snprintf(buf_cur_cart_account,sizeof(buf_cur_cart_account),"%.2f",cur_account);
            buf_cur_cart_account[strlen(buf_cur_cart_account)] = '\0';
            lv_label_set_text(cart->tmp5,buf_cur_cart_account);

            lv_label_set_text(shop_cart_cont->current_amount,buf_cur_cart_account);

            Cart_goods_list *find =  cart_goods_find_node_by_name(cart_goods_list,tmp->name);
            find->quantity=find->quantity-1;
            find->remainder=find->remainder+1;
            if(cart->tmp6 != NULL)
            {
                lv_label_set_text(cart->tmp6,buf_cur_select_goods_num);//当前选择的商品数量
            }
            Shopping_tab_ui(Shopping_cart);
        }else{
            return;
        }
    }
    
}

//购物车显示
void shopping_goods_show_cb(lv_event_t *e)
{
    lv_obj_t *target = lv_event_get_target(e);
    lv_obj_t *curr_cont = lv_event_get_user_data(e); 
    lv_obj_t *label = lv_obj_get_child(target,0);
    char *txt = lv_label_get_text(label);
    
    lv_obj_t *cont = lv_obj_create(curr_cont);
    lv_obj_set_flex_flow(cont,LV_FLEX_FLOW_ROW_WRAP);
    lv_obj_set_size(cont, 650, 330);
    lv_obj_set_style_border_width(cont, 0, 0);
    lv_obj_set_style_pad_all(cont, 0, 0);

    //-----------------购物车------------------
    if(cart_cont == NULL)
    {
        cart_cont = malloc(sizeof(one_cart_cont));
        cart_cont->cont = lv_obj_create(curr_cont);
        lv_obj_set_size(cart_cont->cont, 650, 100);
        lv_obj_set_style_border_width(cart_cont->cont, 0, 0);
        lv_obj_set_style_pad_all(cart_cont->cont, 0, 0);
        lv_obj_align_to(cart_cont->cont,cont,LV_ALIGN_OUT_BOTTOM_MID,0,0);
        lv_obj_set_style_bg_color(cart_cont->cont,lv_palette_main(LV_PALETTE_YELLOW),0);

        cart_cont->img_cont = lv_obj_create(cart_cont->cont);
        lv_obj_set_size(cart_cont->img_cont, 90, 90);
        lv_obj_set_style_border_width(cart_cont->img_cont, 0, 0);
        lv_obj_set_style_pad_all(cart_cont->img_cont, 0, 0);

        //    背景
        cart_cont->img = lv_img_create(cart_cont->img_cont);
        //    设置图片源
        LV_IMG_DECLARE(shopping_cart_img);
        lv_img_set_src(cart_cont->img,&shopping_cart_img);
        lv_obj_set_size(cart_cont->img,90,90);
        lv_obj_align(cart_cont->img,LV_ALIGN_LEFT_MID,5,0);

        //当前金额标签
        cart_cont->current_amount_label = lv_label_create(cart_cont->cont);
        lv_label_set_text(cart_cont->current_amount_label,"current amount:");
        lv_obj_set_style_text_font(cart_cont->current_amount_label,&lv_font_montserrat_20,0);
        lv_obj_align(cart_cont->current_amount_label,LV_ALIGN_RIGHT_MID,-230,0);

        //当前金额
        cart_cont->current_amount = lv_label_create(cart_cont->cont);
        lv_label_set_text(cart_cont->current_amount,"0.0");
        lv_obj_set_style_text_font(cart_cont->current_amount,&lv_font_montserrat_20,0);
        lv_obj_align(cart_cont->current_amount,LV_ALIGN_RIGHT_MID,-175,0);

    }
    /*------------------------------------------------*/
    Goodslist *tmp = goods_list->next;
    for(;tmp!=NULL;tmp=tmp->next)
    {
        if(strcmp(tmp->type,txt) != 0)
        {
            continue;
        }
        lv_obj_t *small_goods_cont = lv_obj_create(cont);
        lv_obj_set_size(small_goods_cont, 630, 110);
        lv_obj_set_style_border_width(small_goods_cont, 0, 0);
        lv_obj_set_style_pad_all(small_goods_cont, 0, 0);
        lv_obj_set_style_bg_color(small_goods_cont,lv_palette_main(LV_PALETTE_CYAN),0);

        lv_obj_t *goods_img_cont = lv_obj_create(small_goods_cont);
        lv_obj_set_size(goods_img_cont, 100, 100);
        lv_obj_set_style_border_width(goods_img_cont, 0, 0);
        lv_obj_set_style_pad_all(goods_img_cont, 0, 0);
        lv_obj_align(goods_img_cont,LV_ALIGN_LEFT_MID,5,0);
        lv_obj_set_style_bg_color(goods_img_cont,lv_palette_main(LV_PALETTE_GREY),0);
        //商品名称
        lv_obj_t *goods_name_label = lv_label_create(small_goods_cont);
        lv_label_set_text(goods_name_label,tmp->name);
        lv_obj_set_style_text_font(goods_name_label,&lv_font_montserrat_20,0);
        lv_obj_set_size(goods_name_label, 100, 40);
        lv_obj_align_to(goods_name_label,goods_img_cont,LV_ALIGN_OUT_RIGHT_MID,20,-20);

        //剩余标签
        lv_obj_t *goods_quan_label = lv_label_create(small_goods_cont);
        lv_label_set_text(goods_quan_label,"Remaining:");
        lv_obj_set_style_text_font(goods_quan_label,&lv_font_montserrat_20,0);
        lv_obj_align_to(goods_quan_label,goods_img_cont,LV_ALIGN_OUT_RIGHT_MID,20,20);

        //商品剩余
        lv_obj_t *goods_quantity_label = lv_label_create(small_goods_cont);
        char quantity_str[20];
        snprintf(quantity_str,sizeof(quantity_str),"%d",tmp->quantity);
        lv_label_set_text(goods_quantity_label,quantity_str);
        lv_obj_set_style_text_font(goods_quantity_label,&lv_font_montserrat_20,0);
        lv_obj_set_size(goods_quantity_label, 50, 40);
        lv_obj_align_to(goods_quantity_label,goods_img_cont,LV_ALIGN_OUT_RIGHT_MID,145,30);

        //价格标签
        lv_obj_t *goods_pr_label = lv_label_create(small_goods_cont);
        lv_label_set_text(goods_pr_label,"price:");
        lv_obj_set_style_text_font(goods_pr_label,&lv_font_montserrat_20,0);
        lv_obj_align_to(goods_pr_label,goods_name_label,LV_ALIGN_OUT_RIGHT_MID,0,0);
        //商品价格
        char price_str[20];
        snprintf(price_str,sizeof(price_str),"%.2f",tmp->price);
        lv_obj_t *goods_price_label = lv_label_create(small_goods_cont);
        lv_label_set_text(goods_price_label,price_str);
        lv_obj_set_style_text_font(goods_price_label,&lv_font_montserrat_20,0);
        lv_obj_align_to(goods_price_label,goods_pr_label,LV_ALIGN_OUT_RIGHT_MID,8,0);

        //添加
        lv_obj_t *add_btn = lv_btn_create(small_goods_cont);
        lv_obj_align(add_btn,LV_ALIGN_RIGHT_MID,-100,0);
        lv_obj_set_style_radius(add_btn,20,0);
        lv_obj_set_size(add_btn,40,40);
        
        lv_obj_t *add_label = lv_label_create(add_btn);
        lv_label_set_text(add_label,LV_SYMBOL_PLUS);
        lv_obj_center(add_label);
        //移除
        lv_obj_t *reduce_btn = lv_btn_create(small_goods_cont);
        lv_obj_set_size(reduce_btn,40,40);
        lv_obj_align(reduce_btn,LV_ALIGN_RIGHT_MID,-30,0);
        lv_obj_set_style_radius(reduce_btn,20,0);
        lv_obj_t *reduce_label = lv_label_create(reduce_btn);
        lv_label_set_text(reduce_label,LV_SYMBOL_MINUS);
        lv_obj_center(reduce_label);

        //数量
        lv_obj_t *cur_num = lv_label_create(small_goods_cont);
        lv_label_set_text(cur_num,"0");
        lv_obj_align_to(cur_num,add_btn,LV_ALIGN_OUT_RIGHT_MID,10,0);

        goods_cart *goods_data =malloc(sizeof(goods_cart));
        if (goods_data == NULL) {
            printf("Memory allocation failed\n");
            return;
        }
        goods_data->tmp1 = goods_name_label;
        goods_data->tmp2 = goods_price_label;
        goods_data->tmp3 = goods_quantity_label;
        goods_data->tmp4 = cur_num;
        goods_data->tmp5 = cart_cont->current_amount;

        lv_obj_add_event_cb(add_btn,add_or_reduce_to_cart_event_cb,LV_EVENT_CLICKED,goods_data);
        lv_obj_add_event_cb(reduce_btn,add_or_reduce_to_cart_event_cb,LV_EVENT_CLICKED,goods_data);

    }

    //结账按钮
    lv_obj_t *check_out_btn = lv_btn_create(cart_cont->cont);
    lv_obj_set_size(check_out_btn,100,40);
    lv_obj_align(check_out_btn,LV_ALIGN_RIGHT_MID,-30,0);

    lv_obj_t *check_out_label = lv_label_create(check_out_btn);
    lv_label_set_text(check_out_label,"Check Out");
    lv_obj_center(check_out_label);

    lv_obj_add_event_cb(check_out_btn,create_check_out_window,LV_EVENT_CLICKED,cart_cont->current_amount);

}

//购物界面
void Goods_tab_ui(lv_obj_t *e)
{
    lv_obj_t *Goods_tab = e;
    // 2.Goods_tab :商品
    lv_obj_set_style_border_width(Goods_tab, 0, 0);
    lv_obj_set_style_pad_all(Goods_tab, 0, 0);
    lv_obj_t *type_list = lv_list_create(Goods_tab);
    lv_obj_set_size(type_list,150,430);
    lv_obj_set_align(type_list, LV_ALIGN_TOP_LEFT);

    // 2.1种类按钮
    lv_obj_t *btn1 = lv_list_add_btn(type_list, NULL , "snacks");
    lv_obj_t *btn2 = lv_list_add_btn(type_list, NULL , "Fruit");
    lv_obj_t *btn3 = lv_list_add_btn(type_list, NULL , "vegetables");
    lv_obj_t *btn4 = lv_list_add_btn(type_list, NULL , "Household");
    lv_obj_t *btn5 = lv_list_add_btn(type_list, NULL , "Beverage");
    lv_obj_t *btn6 = lv_list_add_btn(type_list, NULL , "clothing");

    lv_obj_t *goods_scr = lv_obj_create(Goods_tab);
    lv_obj_set_size(goods_scr,650,430);
    lv_obj_set_align(goods_scr, LV_ALIGN_TOP_RIGHT);
    lv_obj_set_style_border_width(goods_scr, 0, 0);
    lv_obj_set_style_pad_all(goods_scr, 0, 0);
    //    背景
    lv_obj_t *img = lv_img_create(goods_scr);
    lv_obj_set_style_border_width(img, 0, 0);
    lv_obj_set_style_pad_all(img, 0, 0);
    //    设置图片源
    LV_IMG_DECLARE(shopping_img);
    lv_img_set_src(img,&shopping_img);
    lv_obj_set_size(img,650,430);

    lv_obj_add_event_cb(btn1,shopping_goods_show_cb,LV_EVENT_CLICKED,goods_scr);
    lv_obj_add_event_cb(btn2,shopping_goods_show_cb,LV_EVENT_CLICKED,goods_scr);
    lv_obj_add_event_cb(btn3,shopping_goods_show_cb,LV_EVENT_CLICKED,goods_scr);
    lv_obj_add_event_cb(btn4,shopping_goods_show_cb,LV_EVENT_CLICKED,goods_scr);
    lv_obj_add_event_cb(btn5,shopping_goods_show_cb,LV_EVENT_CLICKED,goods_scr);
    lv_obj_add_event_cb(btn6,shopping_goods_show_cb,LV_EVENT_CLICKED,goods_scr);
}

//购物车界面
void Shopping_tab_ui(lv_obj_t *e)
{
    lv_obj_t *Shopping_tab = e;
    // 2.Shopping_tab :购物车

    lv_obj_set_style_border_width(Shopping_tab, 0, 0);
    lv_obj_set_style_pad_all(Shopping_tab, 0, 0);

    lv_obj_t *shopping_cart_scr = lv_obj_create(Shopping_tab);
    lv_obj_set_flex_flow(shopping_cart_scr,LV_FLEX_FLOW_ROW_WRAP);
    lv_obj_set_size(shopping_cart_scr,800,330);
    lv_obj_set_align(shopping_cart_scr, LV_ALIGN_TOP_MID);
    lv_obj_set_style_border_width(shopping_cart_scr, 0, 0);
    lv_obj_set_style_pad_all(shopping_cart_scr, 0, 0);

    if(shop_cart_cont == NULL)
    {

        shop_cart_cont = malloc(sizeof(one_cart_cont));
        shop_cart_cont->cont = lv_obj_create(Shopping_tab);
        // shop_cart = cart_cont->cont;
        lv_obj_set_size(shop_cart_cont->cont, 800, 100);
        lv_obj_set_style_border_width(shop_cart_cont->cont, 0, 0);
        lv_obj_set_style_pad_all(shop_cart_cont->cont, 0, 0);
        lv_obj_align_to(shop_cart_cont->cont,shopping_cart_scr,LV_ALIGN_OUT_BOTTOM_MID,0,0);
        lv_obj_set_style_bg_color(shop_cart_cont->cont,lv_palette_main(LV_PALETTE_YELLOW),0);

        shop_cart_cont->img_cont = lv_obj_create(shop_cart_cont->cont);
        lv_obj_set_size(shop_cart_cont->img_cont, 90, 90);
        lv_obj_set_style_border_width(shop_cart_cont->img_cont, 0, 0);
        lv_obj_set_style_pad_all(shop_cart_cont->img_cont, 0, 0);

        //    背景
        shop_cart_cont->img = lv_img_create(shop_cart_cont->img_cont);
        //    设置图片源
        LV_IMG_DECLARE(shopping_cart_img);
        lv_img_set_src(shop_cart_cont->img,&shopping_cart_img);
        lv_obj_set_size(shop_cart_cont->img,90,90);
        lv_obj_align(shop_cart_cont->img,LV_ALIGN_LEFT_MID,5,0);

        //当前金额标签
        shop_cart_cont->current_amount_label = lv_label_create(shop_cart_cont->cont);
        lv_label_set_text(shop_cart_cont->current_amount_label,"current amount:");
        lv_obj_set_style_text_font(shop_cart_cont->current_amount_label,&lv_font_montserrat_20,0);
        lv_obj_align(shop_cart_cont->current_amount_label,LV_ALIGN_RIGHT_MID,-230,0);

        //当前金额
        shop_cart_cont->current_amount = lv_label_create(shop_cart_cont->cont);
        // char *txt = lv_label_get_text(cart_cont->current_amount);
        lv_label_set_text(shop_cart_cont->current_amount,"0.0");
        lv_obj_set_style_text_font(shop_cart_cont->current_amount,&lv_font_montserrat_20,0);
        lv_obj_align(shop_cart_cont->current_amount,LV_ALIGN_RIGHT_MID,-175,0);
    }
    
    // Cart_goods_list *tmps = cart_goods_list->next;
    // for(;tmps!=NULL;tmps=tmps->next)
    // {
    //     printf("tmps->name = %s\n",tmps->name);
    // }

    Cart_goods_list *tmp_goods = cart_goods_list->next;
    for(;tmp_goods!=NULL;tmp_goods=tmp_goods->next)
    {
        if(tmp_goods->quantity == 0)
        {
            continue;
        }
        Goodslist *tmp = find_node_by_name(goods_list,tmp_goods->name);
        lv_obj_t *small_goods_cont = lv_obj_create(shopping_cart_scr);
        lv_obj_set_size(small_goods_cont, 800, 110);
        lv_obj_set_style_border_width(small_goods_cont, 0, 0);
        lv_obj_set_style_pad_all(small_goods_cont, 0, 0);
        lv_obj_set_style_bg_color(small_goods_cont,lv_palette_main(LV_PALETTE_CYAN),0);

        lv_obj_t *goods_img_cont = lv_obj_create(small_goods_cont);
        lv_obj_set_size(goods_img_cont, 100, 100);
        lv_obj_set_style_border_width(goods_img_cont, 0, 0);
        lv_obj_set_style_pad_all(goods_img_cont, 0, 0);
        lv_obj_align(goods_img_cont,LV_ALIGN_LEFT_MID,5,0);
        lv_obj_set_style_bg_color(goods_img_cont,lv_palette_main(LV_PALETTE_GREY),0);
        //商品名称
        lv_obj_t *goods_name_label = lv_label_create(small_goods_cont);
        lv_label_set_text(goods_name_label,tmp->name);
        lv_obj_set_style_text_font(goods_name_label,&lv_font_montserrat_20,0);
        lv_obj_set_size(goods_name_label, 100, 40);
        lv_obj_align_to(goods_name_label,goods_img_cont,LV_ALIGN_OUT_RIGHT_MID,20,-20);


        //价格标签
        lv_obj_t *goods_pr_label = lv_label_create(small_goods_cont);
        lv_label_set_text(goods_pr_label,"price:");
        lv_obj_set_style_text_font(goods_pr_label,&lv_font_montserrat_20,0);
        lv_obj_align_to(goods_pr_label,goods_name_label,LV_ALIGN_OUT_RIGHT_MID,0,0);
        //商品价格
        char price_str[20];
        snprintf(price_str,sizeof(price_str),"%.2f",tmp->price);
        lv_obj_t *goods_price_label = lv_label_create(small_goods_cont);
        lv_label_set_text(goods_price_label,price_str);
        lv_obj_set_style_text_font(goods_price_label,&lv_font_montserrat_20,0);
        lv_obj_align_to(goods_price_label,goods_pr_label,LV_ALIGN_OUT_RIGHT_MID,8,0);

        //添加
        lv_obj_t *add_btn = lv_btn_create(small_goods_cont);
        lv_obj_align(add_btn,LV_ALIGN_RIGHT_MID,-100,0);
        lv_obj_set_style_radius(add_btn,20,0);
        lv_obj_set_size(add_btn,40,40);
        
        lv_obj_t *add_label = lv_label_create(add_btn);
        lv_label_set_text(add_label,LV_SYMBOL_PLUS);
        lv_obj_center(add_label);
        //移除
        lv_obj_t *reduce_btn = lv_btn_create(small_goods_cont);
        lv_obj_set_size(reduce_btn,40,40);
        lv_obj_align(reduce_btn,LV_ALIGN_RIGHT_MID,-30,0);
        lv_obj_set_style_radius(reduce_btn,20,0);
        lv_obj_t *reduce_label = lv_label_create(reduce_btn);
        lv_label_set_text(reduce_label,LV_SYMBOL_MINUS);
        lv_obj_center(reduce_label);

        //数量
        lv_obj_t *cur_num = lv_label_create(small_goods_cont);
        char quantity_str[20];
        snprintf(quantity_str,sizeof(quantity_str),"%d",tmp_goods->quantity);

        lv_label_set_text(cur_num,quantity_str);
        lv_obj_align_to(cur_num,add_btn,LV_ALIGN_OUT_RIGHT_MID,10,0);

        goods_cart *goods_data =malloc(sizeof(goods_cart));
        if (goods_data == NULL) {
            printf("Memory allocation failed\n");
            return;
        }
        goods_data->tmp1 = goods_name_label;//购物车中的商品名称
        goods_data->tmp2 = goods_price_label;//购物车中的商品价格
        goods_data->tmp3 = tmp_goods->remainder_label;//购物中的商品剩余
        goods_data->tmp4 = cur_num;//购物车中选择的商品数量
        goods_data->tmp5 = cart_cont->current_amount;//购物中的总价
        goods_data->tmp6 = tmp_goods->quantity_label;//购物中的商品数量

        lv_obj_add_event_cb(add_btn,add_or_reduce_to_cart_event_cb,LV_EVENT_CLICKED,goods_data);
        lv_obj_add_event_cb(reduce_btn,add_or_reduce_to_cart_event_cb,LV_EVENT_CLICKED,goods_data);

    }

    //结账按钮
    lv_obj_t *check_out_btn = lv_btn_create(shop_cart_cont->cont);
    lv_obj_set_size(check_out_btn,100,40);
    lv_obj_align(check_out_btn,LV_ALIGN_RIGHT_MID,-30,0);

    lv_obj_t *check_out_label = lv_label_create(check_out_btn);
    lv_label_set_text(check_out_label,"Check Out");
    lv_obj_center(check_out_label);

    lv_obj_add_event_cb(check_out_btn,create_check_out_window,LV_EVENT_CLICKED,shop_cart_cont->current_amount);
}

//退出登录
void log_out_event_cb(lv_event_t *e)
{
    cart_cont = NULL;//刷新购物界面购物车
    shop_cart_cont = NULL;//刷新购物车界面购物车
    Identity_choice();
}

//充值回调
void top_up_event_cb(lv_event_t *e)
{
    lv_obj_t *target = lv_event_get_target(e);
    lv_obj_t *data = lv_event_get_user_data(e);
    char *amount_str = lv_textarea_get_text(data);
    float amount =  atof(amount_str);
    User *tmp = user_find_node_by_username(user_list,cur_user.username);
    
    tmp->balance = tmp->balance+amount;
    user_file_save_data(user_list,"user.txt");
    cur_login_user_info(tmp);
    lv_obj_t * mbox = lv_msgbox_create(NULL, "success", "Recharge successful", NULL, true);
    lv_obj_center(mbox);
    user_ui_init();
}

//充值
void Top_up_wallet_event_ui(lv_event_t *e)
{
    // 创建模态背景窗口
    lv_obj_t *Top_up = lv_win_create(lv_scr_act(), 50);
    lv_obj_set_size(Top_up, 800, 480);
    lv_obj_center(Top_up);
    lv_win_add_title(Top_up, "Top up ui");
    // 关闭标志
    lv_obj_t *close_btn = lv_win_add_btn(Top_up, LV_SYMBOL_CLOSE, 50);
    lv_obj_add_event_cb(close_btn, close_pay_win_event, LV_EVENT_CLICKED, Top_up);

    lv_obj_t *payment_scr = lv_obj_create(Top_up);
    lv_obj_set_size(payment_scr,800,430);
    lv_obj_set_style_border_width(payment_scr, 0, 0);
    lv_obj_set_style_pad_all(payment_scr, 0, 0);
    //    背景
    lv_obj_t *img = lv_img_create(payment_scr);
    //    设置图片源
    LV_IMG_DECLARE(check_out_bg_img);
    lv_img_set_src(img,&check_out_bg_img);
    lv_obj_set_size(img,800,430);

    lv_obj_t *payment_ta = lv_textarea_create(payment_scr);
    lv_obj_set_size(payment_ta, 300, 40);
    lv_obj_align(payment_ta, LV_ALIGN_TOP_MID, 0, 50);
    lv_obj_remove_style(payment_ta, NULL, LV_PART_SCROLLBAR);    //移除滚动条样式
    lv_textarea_set_placeholder_text(payment_ta, "Amount");//占位符的内容
    lv_obj_add_event_cb(payment_ta, keyboard_event_cb, LV_EVENT_ALL,NULL);//键盘

    //键盘
    keyboard = lv_keyboard_create(lv_scr_act());
    lv_keyboard_set_textarea(keyboard, NULL);
    lv_obj_add_flag(keyboard, LV_OBJ_FLAG_HIDDEN);

    lv_obj_t * Top_up_wallet_btn = lv_btn_create(payment_scr);
    lv_obj_set_size(Top_up_wallet_btn,100,40);
    lv_obj_set_style_border_width(Top_up_wallet_btn, 0, 0);
    lv_obj_set_style_pad_all(Top_up_wallet_btn, 0, 0);
    lv_obj_align(Top_up_wallet_btn,LV_ALIGN_TOP_MID,0,120);
    lv_obj_add_event_cb(Top_up_wallet_btn,top_up_event_cb,LV_EVENT_CLICKED,payment_ta);

    lv_obj_t *Top_up_wallet_label =  lv_label_create(Top_up_wallet_btn);
    lv_label_set_text(Top_up_wallet_label,"top up");
    lv_obj_center(Top_up_wallet_label);    
}

//用户ui
void User_tab_ui(lv_obj_t *e)
{
    lv_obj_t *User_tab = e;
    // 2.User_tab :账户信息
    lv_obj_set_style_border_width(User_tab, 0, 0);
    lv_obj_set_style_pad_all(User_tab, 0, 0);

    //容器
    lv_obj_t *User_scr = lv_obj_create(User_tab);
    lv_obj_set_size(User_scr,800,430);
    lv_obj_set_align(User_scr, LV_ALIGN_TOP_MID);
    lv_obj_set_style_border_width(User_scr, 0, 0);
    lv_obj_set_style_pad_all(User_scr, 0, 0);

    //    背景
    lv_obj_t *user_bg = lv_img_create(User_scr);
    lv_obj_set_style_border_width(user_bg, 0, 0);
    lv_obj_set_style_pad_all(user_bg, 0, 0);
    //    设置图片源
    LV_IMG_DECLARE(user_bg_img);
    lv_img_set_src(user_bg,&user_bg_img);
    lv_obj_set_size(user_bg,800,430);

    // 个人头像
    lv_obj_t *user_profile = lv_img_create(User_scr);
    lv_obj_set_style_border_width(user_profile, 0, 0);
    lv_obj_set_style_pad_all(user_profile, 0, 0);
    //    设置图片源
    LV_IMG_DECLARE(user_img);
    lv_img_set_src(user_profile,&user_img);
    lv_obj_set_size(user_profile,100,100);
    lv_obj_set_style_radius(user_profile,30,0);
    lv_obj_set_style_clip_corner(user_profile,50,0);
    lv_obj_align(user_profile,LV_ALIGN_TOP_MID,0,10);
    //user info
    lv_obj_t *user_info_cont = lv_obj_create(User_scr);
    lv_obj_set_size(user_info_cont,250,300);
    lv_obj_align_to(user_info_cont,user_profile,LV_ALIGN_OUT_BOTTOM_MID,0,10);
    
    lv_obj_t *user_name_label =  lv_label_create(user_info_cont);
    char username [50];
    snprintf(username,sizeof(username),"username:  %s",cur_user.username);
    lv_label_set_text(user_name_label,username);
    lv_obj_align(user_name_label,LV_ALIGN_TOP_MID,0,10);

    //身份
    lv_obj_t *user_identity_label =  lv_label_create(user_info_cont);
    if(cur_user.identity == 1)
    {
        lv_label_set_text(user_identity_label,"Identity: ordinary user");
    }else if(cur_user.identity == 2)
    {
        lv_label_set_text(user_identity_label,"Identity: VIP user");
    }
    lv_obj_align(user_identity_label,LV_ALIGN_TOP_MID,0,40);

    //积分
    lv_obj_t *user_credits_label =  lv_label_create(user_info_cont);
    char user_credits [50];
    snprintf(user_credits,sizeof(user_credits),"credits:  %d",cur_user.credits);
    lv_label_set_text(user_credits_label,user_credits);
    lv_obj_align(user_credits_label,LV_ALIGN_TOP_MID,0,70);

    //总消耗金额
    lv_obj_t *user_Total_consumption_label =  lv_label_create(user_info_cont);
    char user_Total_consumption [50];
    snprintf(user_Total_consumption,sizeof(user_Total_consumption),"consumption:  %.2f",cur_user.Total_consumption);
    lv_label_set_text(user_Total_consumption_label,user_Total_consumption);
    lv_obj_align(user_Total_consumption_label,LV_ALIGN_TOP_MID,0,100);

    //钱包余额
    lv_obj_t *user_balance_label =  lv_label_create(user_info_cont);
    char user_balance [50];
    snprintf(user_balance,sizeof(user_balance),"balance:  %.2f",cur_user.balance);
    lv_label_set_text(user_balance_label,user_balance);
    lv_obj_align(user_balance_label,LV_ALIGN_TOP_MID,0,130);

    //钱包充值
    lv_obj_t * Top_up_wallet_btn = lv_btn_create(user_info_cont);
    lv_obj_set_size(Top_up_wallet_btn,100,40);
    lv_obj_set_style_border_width(Top_up_wallet_btn, 0, 0);
    lv_obj_set_style_pad_all(Top_up_wallet_btn, 0, 0);
    lv_obj_align(Top_up_wallet_btn,LV_ALIGN_TOP_MID,0,160);
    lv_obj_add_event_cb(Top_up_wallet_btn,Top_up_wallet_event_ui,LV_EVENT_CLICKED,NULL);

    lv_obj_t *Top_up_wallet_label =  lv_label_create(Top_up_wallet_btn);
    lv_label_set_text(Top_up_wallet_label,"top up");
    lv_obj_center(Top_up_wallet_label);    
    //退出登录
    lv_obj_t * Log_out_btn = lv_btn_create(user_info_cont);
    lv_obj_set_size(Log_out_btn,100,40);
    lv_obj_set_style_border_width(Log_out_btn, 0, 0);
    lv_obj_set_style_pad_all(Log_out_btn, 0, 0);
    lv_obj_align(Log_out_btn,LV_ALIGN_TOP_MID,0,210);

    lv_obj_t *Log_out_label =  lv_label_create(Log_out_btn);
    lv_label_set_text(Log_out_label,"log out");
    lv_obj_center(Log_out_label);  
    lv_obj_add_event_cb(Log_out_btn,log_out_event_cb,LV_EVENT_CLICKED,NULL);

}

//用户界面初始化
void user_ui_init(void)
{
    //1.tabview实现导航栏
    lv_obj_t *user_tabview = lv_tabview_create(lv_scr_act(),LV_DIR_BOTTOM,50);
    lv_obj_set_size(user_tabview, 800, 480);
    lv_obj_set_style_border_width(user_tabview, 0, 0);
    lv_obj_set_style_pad_all(user_tabview, 0, 0);
    // 1.1导航栏命名
    lv_obj_t *Goods_tab = lv_tabview_add_tab(user_tabview, "Goods");
    Shopping_cart = lv_tabview_add_tab(user_tabview, "Shopping cart");
    User_tab = lv_tabview_add_tab(user_tabview, "User");

    cart_goods_list = cart_goods_init_list();
    Goods_tab_ui(Goods_tab);
    Shopping_tab_ui(Shopping_cart);
    User_tab_ui(User_tab);
    // lv_obj_add_event_cb(user_tabview,tabview_event_cb,LV_EVENT_ALL,NULL);

    //设置当前选中的选项卡
    lv_tabview_set_act(user_tabview, 0, LV_ANIM_OFF);
    

}